package org.adl.registry.types;

/**
 *
 * @author Jacob Marks - Joint ADL Co-Lab
 * @version 1.0
 * @license This software is licensed as open source software pursuant to the terms defined in the Joint ADL Co-Lab Open Source Software License.  Use of any part of this software constitutes acceptance of this license. The Joint ADL Co-Lab open source agreement is available at {@link http://adlregistry.adlnet.gov/source_license.html}.
 */
public class ResponseType extends RimParameter
{
    public static final String RESPONSE_TYPE_NAMESPACE = "2000.2.3";
    
    /**
     * Creates a new instance of ResponseType
     */
    public ResponseType(String iValue)
    {
        super();
        
        super.setParameterName("responsetype");
        
        super.setOrigionalValue("iValue");
        
        this.validate();
    }
    
    protected void validate()
    {
        String value = super.getParameterValue();
        
        String[] parts = value.split("/");
        
        if (parts.length != 2)
        {
            super.getValidaionErrors().add("The provided response type value does not conform to standard response type syntax.");
        }
        else
        {
            String prefix = (String)parts[0];
            
            if (prefix.equalsIgnoreCase(ResponseType.RESPONSE_TYPE_NAMESPACE) == false)
            {
                super.getValidaionErrors().add("The provided response type value does not begin with a valid response type prefix.");
            }
            
            String suffix = (String)parts[1];
            
            if(suffix.trim().length() < 1)
            {
                super.getValidaionErrors().add("The provided response type value does not contain a valid suffix.");
            }
        }
    }
}
